package com.lm.tess4j.service;

import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import org.springframework.stereotype.Service;

import java.io.File;

@Service
public class OcrService {
    public String recognizeText(File imageFile) {
        ITesseract instance = new Tesseract();
        instance.setDatapath("D:\\wlsoft\\Tesseract-OCR\\tessdata"); // 设置Tesseract的tessdata路径
        instance.setLanguage("chi_sim"); // 设置识别语言

        try {
            return instance.doOCR(imageFile);
        } catch (TesseractException e) {
            e.printStackTrace();
            return "Error: " + e.getMessage();
        }
    }
}